package com.tumanex.socialshare;

import android.content.Context;
import android.content.SharedPreferences;
/**
 * 
 * @author artemka
 *
 */
public class Session {

	private static final String SOC_SETTING = "SocNet:Settings";

	private Context mContext;

	private SharedPreferences mPrefs;
	private SharedPreferences.Editor mEditor;

	public Session(Context context) {

		mContext = context;

		mPrefs = mContext.getSharedPreferences(SOC_SETTING, 0);
		mEditor = mPrefs.edit();

	}

	void saveAccessToken(String accessToken, String expires, String userId) {

		mEditor.putString("AccessToken", accessToken);
		mEditor.putString("ExpiresIn", expires);
		mEditor.putString("UserId", userId);
		mEditor.putLong("AccessTime", System.currentTimeMillis());

		mEditor.commit();

	}

	String[] getAccessToken() {

		String[] params = new String[4];

		params[0] = mPrefs.getString("AccessToken", "");
		params[1] = mPrefs.getString("ExpiresIn", "");
		params[2] = mPrefs.getString("UserId", "");
		params[3] = String.valueOf(mPrefs.getLong("AccessTime", 0));

		return params;

	}

	void resetAccessToken() {

		mEditor.putString("AccessToken", "");
		mEditor.putString("ExpiresIn", "");
		mEditor.putString("UserId", "");
		mEditor.putLong("AccessTime", 0);

		mEditor.commit();

	}

}
